var meeting = {
	Config: {
		/*配置信息*/
		host: "192.168.1.104",
		port: "8080"
	},

	Url: {
		/*URl*/

		getDefaultSiteUrl: function(url) {
			//var netConfig = JSON.parse(plus.storage.getItem("$netConfig") || JSON.stringify(meeting.Config));
			return "http://" + meeting.Config.host + ":" + meeting.Config.port + "/" + url;
		}
	},

	Post: function(url, option) {
		/*ajax请求（Post）*/

		//默认ajax参数
		var ajaxOption = {
			asnyc: false,
			dataType: "json",
			error: function(xhr, type, errorThrown) {
				console.log(url);
				console.log(xhr.responseHTML);
				switch (type) {
					case "timeout":
						//连接超时
						plus.nativeUI.toast("连接超时")
						break;
					case "parsererror":
						//参数格式错误
						plus.nativeUI.toast("参数格式错误")
						return;
				}
			},
			success: function(data, status, xhr) {},
			timeout: 60000,
			type: 'POST',
			headers: {
				'Content-Type': 'application/json'
			}
		}

		//合并传入参数
		mui.extend(ajaxOption, option);

		//ajax请求
		mui.ajax(url, ajaxOption);
	},

	Get: function(url, option) {
		/*ajax请求（GET）*/

		//默认ajax参数
		var ajaxOption = {
			asnyc: false,
			dataType: "json",
			error: function(xhr, type, errorThrown) {

				console.log(type)
				switch (type) {
					case "timeout":
						//链接超时
						break;
					case "parsererror":
						//参数格式错误
						return;
				}
			},
			success: function(data, status, xhr) {},
			timeout: 60000,
			type: 'GET'
		}

		//合并传入参数
		mui.extend(ajaxOption, option);

		//ajax请求
		mui.ajax(url, ajaxOption);
	},
	Form: {
		openWindow: function openPage(id, caption, extras, showmenu) {

			var styles = {
				titleNView: {
					titleText: caption,
					/* titleColor: "#ffffff", */
					titleSize: "16px",
					/* backgroundColor: '#2662A3', */
					autoBackButton: true
				}
			}

/* 			if (showmenu) {
				styles.titleNView.buttons = [{
					text: "\ue563",
					fontSize: 27,
					fontSrc: "/fonts/mui.ttf",
					float: "right",
					onclick: function() {
						plus.webview.getWebviewById(id).evalJS(
							"mui('#menu-popover').popover('toggle',document.getElementById('openPopover'));")
					}
				}]
			} */

			var wv = plus.webview.create(id + '.html', id, styles, extras);
			wv.show();
		},
		valid: function(el) {
			var isvalid = true;
			var message = "";

			mui(el + " input").each(function() {
				var isrequired = this.hasAttribute("required");

				if (isrequired) {
					if (!this.value || this.value.trim() == "") {
						message += this.getAttribute("requiredmessage") + "\n";
						isvalid = false;
					}
				}
			});

			if (!isvalid) {
				plus.nativeUI.toast(message);
			}

			return isvalid;
		},
		loadControllVal: function(el, data) {
			mui(el + " input," + el + " textarea").each(function() {
				if (this.hasAttribute("name")) {
					if (data.hasOwnProperty(this.getAttribute("name"))) {
						this.value = data[this.getAttribute("name")];
					}
				}
			});
		},
		serial: function(el) {
			var obj = {};
			mui(el + " input," + el + " textarea").each(function() {
				if (this.hasAttribute("name")) {
					obj[this.getAttribute("name")] = this.value;
				}
			});

			return obj;
		},
		clear: function(el) {
			mui(el + " input").each(function() {
				this.value = '';
			});
		}
	},
	mui: {
		pullRefresh: function(el, refreshCallBack) {
			mui.init({
				pullRefresh: {
					container: el, //下拉刷新容器标识，querySelector能定位的css选择器均可，比如：id、.class等
					down: {
						height: 50, //可选,默认50.触发下拉刷新拖动距离,
						auto: true, //可选,默认false.自动下拉刷新一次
						contentdown: "下拉可以刷新", //可选，在下拉可刷新状态时，下拉刷新控件上显示的标题内容
						contentover: "释放立即刷新", //可选，在释放可刷新状态时，下拉刷新控件上显示的标题内容
						contentrefresh: "正在刷新...", //可选，正在刷新状态时，下拉刷新控件上显示的标题内容
						callback: refreshCallBack //function 必选，刷新函数，根据具体业务来编写，比如通过ajax从服务器获取新数据；
					}
				}
			});
		}
	},
	UI: {
		IndexedList: {
			first: function(el, data, attrlist) {
				var bartitle = "";

				//清除上次选中信息
				mui(el + " .mui-indexed-list-bar")[0].innerHTML = '';
				mui(el + " .mui-table-view")[0].innerHTML = '';
				mui(el + " input[type='search']")[0].value = '';
				/*				if(window.indexedList) {
									window.indexedList.search('');
								}*/
				var done = document.getElementById('done');
				done.innerHTML = '完成';
				if (!done.classList.contains("mui-disabled")) {
					done.classList.add("mui-disabled");
				}

				//加载选项
				for (var i = 0; i < data.length; i++) {
					var obj = data[i];

					//添加首字母索引
					var groupName = obj.groupName.length > 2 ? obj.groupName.substr(0, 2) : obj.groupName
					if (groupName != bartitle) {
						bartitle = groupName;

						var barnode = document.createElement("a");
						barnode.innerHTML = bartitle;
						mui(el + " .mui-indexed-list-bar")[0].appendChild(barnode);

						var viewgroup = document.createElement("li");
						viewgroup.className = "mui-table-view-divider mui-indexed-list-group";
						viewgroup.innerHTML = bartitle;
						viewgroup.setAttribute("data-group", bartitle);
						mui(el + " .mui-table-view")[0].appendChild(viewgroup);
					}

					//加载选项内容
					var item = document.createElement("li");
					item.className = "mui-table-view-cell mui-indexed-list-item mui-checkbox mui-left";
					item.innerHTML = '<input type="checkbox" />' + obj.name + '</li>';
					item.setAttribute("data-value", obj.id);
					if (attrlist) {
						for (var j = 0; j < attrlist.length; j++) {
							item.setAttribute("data-" + attrlist[j], obj[attrlist[j]]);
						}
					}
					mui(el + " .mui-table-view")[0].appendChild(item);
				}
			}
		}
	}
}
